
import time
import datetime


def date_to_timestamp(start_date=None, end_date=None):
    """
    时期转换为时间戳

    :param start_date: 开始日期 -> 2019-8-1
    :param end_date: 结束日期 -> 2019-8-2
    :return:
    """

    if start_date is None and end_date is None:
        today_date = time.strftime('%Y-%m-%d')
        s_time = '%s 00:00:00' % today_date
        e_time = '%s 23:59:59' % today_date
    else:
        s_time = '%s 00:00:00' % start_date
        e_time = '%s 23:59:59' % end_date

    s_stamp = time.mktime(time.strptime(s_time, "%Y-%m-%d %H:%M:%S"))
    e_stamp = time.mktime(time.strptime(e_time, "%Y-%m-%d %H:%M:%S"))
    return int(s_stamp), int(e_stamp)


def get_current_timestamp():
    """
    获取当前时间戳
    :return:
    """
    return int(time.time() * 1000)


def get_current_time():
    """
    获取指定格式的当前时间
    """
    return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')


def get_today_timestamp():
    """
    获取当天0点时间戳
    """
    day_timestamp = int(time.mktime(datetime.date.today().timetuple()) * 1000)
    return day_timestamp


def get_given_timestamp(days):
    """
    获取特定日期的时间戳
    """
    today = datetime.date.today()
    given_day = today + datetime.timedelta(days=days-1)
    given_timestamp = int(time.mktime(time.strptime(str(given_day), '%Y-%m-%d')) * 1000)
    return given_timestamp


def getTime(timestamp):
    """
    时间戳转换为标准时间格式
    """
    # 转换成localtime
    time_local = time.localtime(timestamp)
    stadardTime = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
    return stadardTime


def convert_sec(sec):
    """
    秒转换为时分
    :param sec: int
    :return:
    """
    return str(datetime.timedelta(seconds=sec))


def get_current_date():
    """
    获取指定格式的当前时间
    """
    return datetime.datetime.now().strftime('%Y-%m-%d')


if __name__ == '__main__':

    print(get_current_date())



